import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
from PyQt5.QtCore import Qt
from socket_push import start_server, stop_server
from threading import Thread

class MyApp(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        # 创建启动按钮
        start_button = QPushButton('启动', self)
        start_button.setStyleSheet("background-color: green; color: white;")
        start_button.clicked.connect(self.start_action)

        # 创建停止按钮
        stop_button = QPushButton('停止', self)
        stop_button.setStyleSheet("background-color: red; color: white;")
        stop_button.clicked.connect(self.stop_action)

        # 布局
        vbox = QVBoxLayout()
        vbox.addWidget(start_button)
        vbox.addWidget(stop_button)

        self.setLayout(vbox)

        self.setWindowTitle('PyQt5 Button Example')
        self.setGeometry(300, 300, 300, 200)
        self.show()

    def start_action(self):
        print("启动按钮被按下")
        Thread(target=start_server).start()

    def stop_action(self):
        print("停止按钮被按下")
        stop_server()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyApp()
    sys.exit(app.exec_())
